import React from 'react'

import Api from '../router/Api'

import '../public/css/loginout.scss'
import '../public/js/requestSign'
import requestSign from "../public/js/requestSign";


class Loginout extends React.Component{
    constructor(props){
        super(props);
    }
    handleClose(){
        this.props.isDialog("false")
    }
    handleLoginout(){
        const token = sessionStorage.getItem('token');
        const _this = this;
        Api.getTimeStamp()
            .then(function (res) {
                const timestamp = res.data.data.timestamp;
                const sign = requestSign({timestamp,token});
                console.log(sign);
                Api.loginout({
                    token:token,
                    timestamp:timestamp,
                    sign:sign.sign
                }).then(function (res) {
                    if(res.data.success){
                        sessionStorage.removeItem('token');
                        window.location.href = "https://www.yd-jr.cn/"
                    }else{
                        console.log(0);
                    }
                })
            })
            .catch(function (err) {
            console.log(err);
            })



    }

    render(){
        return(
            <div className={(this.props.dialog === 'true') ? "dialog" : "dialog hide"}>
                <div className="mask"></div>
                <div>
                    <p>确定要退出吗？</p>
                    <div className="clearFix">
                        <div className={"fl"} onClick={this.handleClose.bind(this)}>取消</div>
                        <div className={"fr"} onClick={this.handleLoginout.bind(this)}>确定</div>
                    </div>
                    <i className="icon iconfont icon-guanbi" onClick={this.handleClose.bind(this)}></i>
                </div>
            </div>
        )
    }
}

export default Loginout